﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.Common;

namespace TravelLink.WebApp {
    public partial class UploadHandler : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            //array("result" 		=> 1, 
            //                     "file" 		=> $_REQUEST['folder'].'/'.$handle->file_dst_name.'?'.time(),
            //                     "imagewidth" 	=> $handle->image_dst_x,
            //                     "imageheight"	=> $handle->image_dst_y
            //                    );

            Dictionary<string, string> dict = new Dictionary<string, string>();

            dict["id"] = "0";
            dict["mess"] = "/img/jiahao1.jpg?time=" + DateTime.Now.Ticks;
            dict["iw"] = "200";
            dict["ih"] = "200";
            if (this.Request.Files.Count > 0) {
                var file = this.Request.Files[0];

                var sitePhoto = PhotoManager.BuildTemplaitePath(Session.SessionID, file.FileName);

                string tempFileName = sitePhoto.OriPhoto.PhysicalPath;

                string resFileName = sitePhoto.ThumbnailPhoto.PhysicalPath;

                file.SaveAs(tempFileName);

                PhotoUtils.CreateThumbnailFile(tempFileName, 200, resFileName);

                dict["mess"] = sitePhoto.ThumbnailPhoto.RelativePath + "?time=" + DateTime.Now.Ticks; ;
            }
            else {
                dict["id"] = "1";
                dict["mess"] = "没有找到上传的文件";
            }




            Response.Write(Interactive.Utility.Serialize.Helper.SerializeString(dict));


            Response.ContentType = "json/text";
            Response.End();
            return;
        }
    }
}